package o;

import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class aka extends ajh {
    private static final Pattern ˊ = Pattern.compile("\\{\\\\.*?\\}");
    private static final Pattern ॱ = Pattern.compile("\\s*((?:(\\d+):)?(\\d+):(\\d+),(\\d+))\\s*-->\\s*((?:(\\d+):)?(\\d+):(\\d+),(\\d+))?\\s*");
    private final ArrayList<String> ˋ = new ArrayList();
    private final StringBuilder ˎ = new StringBuilder();

    protected /* synthetic */ aji ˎ(byte[] bArr, int i, boolean z) throws SubtitleDecoderException {
        return ˏ(bArr, i, z);
    }

    public aka() {
        super("SubripDecoder");
    }

    protected akg ˏ(byte[] bArr, int i, boolean z) {
        ArrayList arrayList = new ArrayList();
        amv o_amv = new amv();
        anc o_anc = new anc(bArr, i);
        while (true) {
            String ˊˋ = o_anc.ˊˋ();
            if (ˊˋ == null) {
                break;
            } else if (ˊˋ.length() != 0) {
                try {
                    Integer.parseInt(ˊˋ);
                    Object ˊˋ2 = o_anc.ˊˋ();
                    if (ˊˋ2 == null) {
                        break;
                    }
                    Matcher matcher = ॱ.matcher(ˊˋ2);
                    if (matcher.matches()) {
                        o_amv.ˋ(ˊ(matcher, 1));
                        if (TextUtils.isEmpty(matcher.group(6))) {
                            ˊˋ2 = null;
                        } else {
                            o_amv.ˋ(ˊ(matcher, 6));
                            ˊˋ2 = 1;
                        }
                        this.ˎ.setLength(0);
                        this.ˋ.clear();
                        while (true) {
                            Object ˊˋ3 = o_anc.ˊˋ();
                            if (TextUtils.isEmpty(ˊˋ3)) {
                                break;
                            }
                            if (this.ˎ.length() > 0) {
                                this.ˎ.append("<br>");
                            }
                            this.ˎ.append(ॱ(ˊˋ3, this.ˋ));
                        }
                        Spanned fromHtml = Html.fromHtml(this.ˎ.toString());
                        for (int i2 = 0; i2 < this.ˋ.size(); i2++) {
                            ˊˋ = (String) this.ˋ.get(i2);
                            if (ˊˋ.matches("\\{\\\\an[1-9]\\}")) {
                                break;
                            }
                        }
                        ˊˋ = null;
                        arrayList.add(ˏ(fromHtml, ˊˋ));
                        if (ˊˋ2 != null) {
                            arrayList.add(null);
                        }
                    } else {
                        amz.ˏ("SubripDecoder", "Skipping invalid timing: " + ˊˋ2);
                    }
                } catch (NumberFormatException e) {
                    amz.ˏ("SubripDecoder", "Skipping invalid index: " + ˊˋ);
                }
            }
        }
        amz.ˏ("SubripDecoder", "Unexpected end");
        Cue[] cueArr = new Cue[arrayList.size()];
        arrayList.toArray(cueArr);
        return new akg(cueArr, o_amv.ˏ());
    }

    private String ॱ(String str, ArrayList<String> arrayList) {
        CharSequence trim = str.trim();
        int i = 0;
        StringBuilder stringBuilder = new StringBuilder(trim);
        Matcher matcher = ˊ.matcher(trim);
        while (matcher.find()) {
            String group = matcher.group();
            arrayList.add(group);
            int start = matcher.start() - i;
            int length = group.length();
            stringBuilder.replace(start, start + length, "");
            i += length;
        }
        return stringBuilder.toString();
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private com.google.android.exoplayer2.text.Cue ˏ(android.text.Spanned r10, @androidx.annotation.Nullable java.lang.String r11) {
        /*
        r9 = this;
        r3 = 3;
        r2 = -1;
        r0 = 2;
        r1 = 1;
        r4 = 0;
        if (r11 != 0) goto L_0x000d;
    L_0x0007:
        r0 = new com.google.android.exoplayer2.text.Cue;
        r0.<init>(r10);
    L_0x000c:
        return r0;
    L_0x000d:
        r5 = r11.hashCode();
        switch(r5) {
            case -685620710: goto L_0x0035;
            case -685620679: goto L_0x0071;
            case -685620648: goto L_0x0053;
            case -685620617: goto L_0x003f;
            case -685620586: goto L_0x007b;
            case -685620555: goto L_0x005d;
            case -685620524: goto L_0x0049;
            case -685620493: goto L_0x0085;
            case -685620462: goto L_0x0067;
            default: goto L_0x0014;
        };
    L_0x0014:
        r5 = r2;
    L_0x0015:
        switch(r5) {
            case 0: goto L_0x0090;
            case 1: goto L_0x0090;
            case 2: goto L_0x0090;
            case 3: goto L_0x0092;
            case 4: goto L_0x0092;
            case 5: goto L_0x0092;
            default: goto L_0x0018;
        };
    L_0x0018:
        r7 = r1;
    L_0x0019:
        r5 = r11.hashCode();
        switch(r5) {
            case -685620710: goto L_0x0094;
            case -685620679: goto L_0x009e;
            case -685620648: goto L_0x00a9;
            case -685620617: goto L_0x00d5;
            case -685620586: goto L_0x00e0;
            case -685620555: goto L_0x00eb;
            case -685620524: goto L_0x00b4;
            case -685620493: goto L_0x00bf;
            case -685620462: goto L_0x00ca;
            default: goto L_0x0020;
        };
    L_0x0020:
        switch(r2) {
            case 0: goto L_0x00f7;
            case 1: goto L_0x00f7;
            case 2: goto L_0x00f7;
            case 3: goto L_0x00fa;
            case 4: goto L_0x00fa;
            case 5: goto L_0x00fa;
            default: goto L_0x0023;
        };
    L_0x0023:
        r5 = r1;
    L_0x0024:
        r0 = new com.google.android.exoplayer2.text.Cue;
        r2 = 0;
        r3 = ˏ(r5);
        r6 = ˏ(r7);
        r8 = 1;
        r1 = r10;
        r0.<init>(r1, r2, r3, r4, r5, r6, r7, r8);
        goto L_0x000c;
    L_0x0035:
        r5 = "{\\an1}";
        r5 = r11.equals(r5);
        if (r5 == 0) goto L_0x0014;
    L_0x003d:
        r5 = r4;
        goto L_0x0015;
    L_0x003f:
        r5 = "{\\an4}";
        r5 = r11.equals(r5);
        if (r5 == 0) goto L_0x0014;
    L_0x0047:
        r5 = r1;
        goto L_0x0015;
    L_0x0049:
        r5 = "{\\an7}";
        r5 = r11.equals(r5);
        if (r5 == 0) goto L_0x0014;
    L_0x0051:
        r5 = r0;
        goto L_0x0015;
    L_0x0053:
        r5 = "{\\an3}";
        r5 = r11.equals(r5);
        if (r5 == 0) goto L_0x0014;
    L_0x005b:
        r5 = r3;
        goto L_0x0015;
    L_0x005d:
        r5 = "{\\an6}";
        r5 = r11.equals(r5);
        if (r5 == 0) goto L_0x0014;
    L_0x0065:
        r5 = 4;
        goto L_0x0015;
    L_0x0067:
        r5 = "{\\an9}";
        r5 = r11.equals(r5);
        if (r5 == 0) goto L_0x0014;
    L_0x006f:
        r5 = 5;
        goto L_0x0015;
    L_0x0071:
        r5 = "{\\an2}";
        r5 = r11.equals(r5);
        if (r5 == 0) goto L_0x0014;
    L_0x0079:
        r5 = 6;
        goto L_0x0015;
    L_0x007b:
        r5 = "{\\an5}";
        r5 = r11.equals(r5);
        if (r5 == 0) goto L_0x0014;
    L_0x0083:
        r5 = 7;
        goto L_0x0015;
    L_0x0085:
        r5 = "{\\an8}";
        r5 = r11.equals(r5);
        if (r5 == 0) goto L_0x0014;
    L_0x008d:
        r5 = 8;
        goto L_0x0015;
    L_0x0090:
        r7 = r4;
        goto L_0x0019;
    L_0x0092:
        r7 = r0;
        goto L_0x0019;
    L_0x0094:
        r3 = "{\\an1}";
        r3 = r11.equals(r3);
        if (r3 == 0) goto L_0x0020;
    L_0x009c:
        r2 = r4;
        goto L_0x0020;
    L_0x009e:
        r3 = "{\\an2}";
        r3 = r11.equals(r3);
        if (r3 == 0) goto L_0x0020;
    L_0x00a6:
        r2 = r1;
        goto L_0x0020;
    L_0x00a9:
        r3 = "{\\an3}";
        r3 = r11.equals(r3);
        if (r3 == 0) goto L_0x0020;
    L_0x00b1:
        r2 = r0;
        goto L_0x0020;
    L_0x00b4:
        r5 = "{\\an7}";
        r5 = r11.equals(r5);
        if (r5 == 0) goto L_0x0020;
    L_0x00bc:
        r2 = r3;
        goto L_0x0020;
    L_0x00bf:
        r3 = "{\\an8}";
        r3 = r11.equals(r3);
        if (r3 == 0) goto L_0x0020;
    L_0x00c7:
        r2 = 4;
        goto L_0x0020;
    L_0x00ca:
        r3 = "{\\an9}";
        r3 = r11.equals(r3);
        if (r3 == 0) goto L_0x0020;
    L_0x00d2:
        r2 = 5;
        goto L_0x0020;
    L_0x00d5:
        r3 = "{\\an4}";
        r3 = r11.equals(r3);
        if (r3 == 0) goto L_0x0020;
    L_0x00dd:
        r2 = 6;
        goto L_0x0020;
    L_0x00e0:
        r3 = "{\\an5}";
        r3 = r11.equals(r3);
        if (r3 == 0) goto L_0x0020;
    L_0x00e8:
        r2 = 7;
        goto L_0x0020;
    L_0x00eb:
        r3 = "{\\an6}";
        r3 = r11.equals(r3);
        if (r3 == 0) goto L_0x0020;
    L_0x00f3:
        r2 = 8;
        goto L_0x0020;
    L_0x00f7:
        r5 = r0;
        goto L_0x0024;
    L_0x00fa:
        r5 = r4;
        goto L_0x0024;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.aka.ˏ(android.text.Spanned, java.lang.String):com.google.android.exoplayer2.text.Cue");
    }

    private static long ˊ(Matcher matcher, int i) {
        return ((((((Long.parseLong(matcher.group(i + 1)) * 60) * 60) * 1000) + ((Long.parseLong(matcher.group(i + 2)) * 60) * 1000)) + (Long.parseLong(matcher.group(i + 3)) * 1000)) + Long.parseLong(matcher.group(i + 4))) * 1000;
    }

    static float ˏ(int i) {
        switch (i) {
            case 0:
                return 0.08f;
            case 1:
                return 0.5f;
            default:
                return 0.92f;
        }
    }
}
